<?php

namespace Base\Controller;
use Common\Base\BaseController;

/**
 * Created by PhpStorm.
 * User: chang
 * Date: 16/5/27
 * Time: 下午1:55
 */
class FileController extends BaseController
{
    public function upload() {
        $upload = new \Think\Upload();
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     C('UPLOAD_PATH'); // 设置附件上传根目录
        $upload->subName = array('date','Ymd');
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件
        $info   =   $upload->upload();
        if(!$info) {
            $this->ajaxReturnWrap(null,1,$upload->getError());
        }else{// 上传成功
            $preview = C('UPLOAD_PATH').$info['file']['savepath'].$info['file']['savename'];
            $this->ajaxReturnWrap($preview,0,'上传成功');
        }
    }
}
